<?php
/************************************
Generate Required Thumbnails
************************************/

function wpboxes_image_setup() {
	add_theme_support( 'post-thumbnails' );
	add_image_size( 'featured', 730, 300, false );
	add_image_size( 'recent', 200, 100, true );
	add_image_size( 'sticky', 150, 150, true );
	add_image_size( 'single', 100, 100, true );
}
add_action( 'after_setup_theme', 'wpboxes_image_setup' );

function wpboxes_custom_image_size( $sizes ) {  
    $custom_sizes = array(  
        'featured' => 'Featured Image Size'  
    );  
    return array_merge( $sizes, $custom_sizes );  
}
add_filter( 'image_size_names_choose', 'wpboxes_custom_image_size' );

/************************************
Featured Image
************************************/
function wpboxes_featured_image() {
	global $post, $posts, $featured_image;
	$id = get_post_thumbnail_id();
	$url = wp_get_attachment_image_src($id,'featured' );
	if (!empty($url)) {
		$featured_image = $url[0]; 
	} else {
		$featured_image = wpboxes_options('wpboxes_dsi');
	}

  return $featured_image;
}

/************************************
Homepage Thumbnails
************************************/
function wpboxes_tn_image() {
	global $post, $posts, $tn_image;
	$id = get_post_thumbnail_id();
	$url = wp_get_attachment_image_src($id,'recent' );
	if (!empty($url)) {
		$tn_image = $url[0]; 
	} elseif (empty($url)) {
		$image = '';
		ob_start();
		ob_end_clean();
		$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
		if (!empty($output)) {
		$tn_image = $matches[1][0];
		} else { $tn_image = wpboxes_options('wpboxes_dtn'); 
	}
}		

  return $tn_image;
}

/************************************
Single Posts Thumbnails
************************************/
function wpboxes_single_tn() {
	global $post, $posts, $hp_thumb;
	$id = get_post_thumbnail_id();
	$url = wp_get_attachment_image_src($id,'recent' );
	if (!empty($url)) {
		$hp_thumb = $url[0]; 
	} elseif (empty($url)) {
		$image = '';
		ob_start();
		ob_end_clean();
		$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
		if (!empty($output)) {
		$hp_thumb = $matches[1][0];
		} else { $hp_thumb = wpboxes_options('wpboxes_dtn'); 
	}
}		

  return $hp_thumb;
}
?>